package pl.vanta.mjuzik.gui.actions;

import java.awt.Window;
import java.awt.event.ActionEvent;

import javax.swing.Action;

import pl.vanta.mjuzik.gui.panels.OptionsPanel;
import pl.vanta.mjuzik.model.Options;
import pl.vanta.mjuzik.services.ConfigurationService;
import pl.vanta.utils.gui.actions.AbstractGuiAction;
import pl.vanta.utils.gui.dialogs.OkCancelDialog;

import com.google.inject.Inject;

public class OptionsAction extends AbstractGuiAction
{
	private static final long	serialVersionUID	= 1L;

	ConfigurationService		configurationService;

	@Inject
	public OptionsAction(Window parent, ConfigurationService configurationService)
	{
		super(parent);

		this.configurationService = configurationService;

		this.putValue(Action.NAME, "Options...");
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		OptionsPanel optionsPanel = new OptionsPanel();
		OkCancelDialog<Options> configDialog = new OkCancelDialog<Options>(this.parent, optionsPanel);

		Options options = configDialog.showDialog(this.configurationService.getOptions());

		if (options != null)
		{
			this.configurationService.setOptions(options);
		}
	}
}